version: '3.1'
services:
  stats-server:
    build: stats/stats-server
    image: stats-server
    container_name: stats-server
    ports:
      - "9090:9090"
    depends_on:
      - stats-db
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://stats-db:5432/ewm-stats
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=root

  stats-db:
    image: postgres:14-alpine
    container_name: stats-db
    ports:
      - "6541:5432"
    environment:
      - POSTGRES_PASSWORD=root
      - POSTGRES_USER=root
      - POSTGRES_DB=ewm-stats

  ewm-service:
    build: main-service
    image: ewm-service
    container_name: ewm-service
    ports:
      - "8080:8080"
    depends_on:
      - ewm-db
      - stats-server
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://ewm-db:5432/ewm-db
      - SPRING_DATASOURCE_USERNAME=root
      - SPRING_DATASOURCE_PASSWORD=root
      - STATS_SERVER_URL=http://stats-server:9090

  ewm-db:
    image: postgres:14-alpine
    container_name: ewm-db
    ports:
      - "6542:5432"
    environment:
      - POSTGRES_PASSWORD=root
      - POSTGRES_USER=root
      - POSTGRES_DB=ewm-db